package net.dipper.tankwar.game.helper;

import java.util.ArrayList;

/*消息管理类*/
public class MessageManager {
	private static MessageManager _instance;
	private static Object _syncRoot = new Object();
	
	private ArrayList<Message> messages;
	
	//获取单一实例
	public static MessageManager getInstance(){
		if(_instance == null){
			synchronized(_syncRoot){
				if(_instance == null){
					_instance = new MessageManager();
				}
			}
		}
		
		return _instance;
	}
	
	private MessageManager(){
		this.messages = new ArrayList<Message>();
	}

	//推送消息
	public void push(Message message) {
		this.messages.add(message);
	}

	//移除消息
	public void remove(Message message){
		this.messages.remove(message);
	}
	
	//获取消息列表副本
	public ArrayList<Message> getMessages() {
		@SuppressWarnings("unchecked")
		ArrayList<Message> clone = (ArrayList<Message>) this.messages.clone();
		return clone;
	}

	//清空消息
	public void clear() {
		this.messages.clear();
	}
	
	
}
